﻿#ifndef VIDEODECODER_H
#define VIDEODECODER_H

#include <QObject>
#include <QMutex>
#include <opencv2/videoio.hpp>
#include <atomic>

class VideoDecoder : public QObject {
    Q_OBJECT
public:
    explicit VideoDecoder(QObject *parent = nullptr);
    ~VideoDecoder();

public slots:
    void open(const QString &filePath);
    void stop();
    void setPosition(int ms);

signals:
    void frameReceived(const QImage &frame);
    void durationChanged(int ms);
    void positionChanged(int ms);

private:
    void decodeLoop();

    cv::VideoCapture m_cap;
    std::atomic<bool> m_running{false};
    std::thread m_decodeThread;
    QMutex m_mutex;
    int m_currentPosition;
};

#endif // VIDEODECODER_H
